package main

import (
	"fmt"
	"strconv"
	"time"
)

func writeChan(pi chan string) {
	for i := 0; i < 10; i++ {
		teststr := fmt.Sprintf("input channel data %s", strconv.Itoa(i))
		pi <- teststr
	}
	fmt.Println("write channel end len:", len(pi))
}
func readChan(pi chan string) {
	var str string
	for i := 0; i < 10; i++ {
		str = <-pi
		fmt.Println("read channel data:", str)
	}
}

func main() {
	var strChan chan string         // 定义管道
	strChan = make(chan string, 10) // 初始化管道的长度
	go writeChan(strChan)           // 启动往管道里写数据的线程
	go readChan(strChan)            // 启动从管道里读数据的线程
	time.Sleep(time.Second)         // sleep 1秒，等两个线程结束
}
